<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>用户总数</span>
            </div>
          </template>
          <div class="card-content">
            <h2>{{ stats.userCount }}</h2>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>单词总数</span>
            </div>
          </template>
          <div class="card-content">
            <h2>{{ stats.wordCount }}</h2>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>分类总数</span>
            </div>
          </template>
          <div class="card-content">
            <h2>{{ stats.categoryCount }}</h2>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>音频文件数</span>
            </div>
          </template>
          <div class="card-content">
            <h2>{{ stats.audioCount }}</h2>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()
const stats = ref({
  userCount: 0,
  wordCount: 0,
  categoryCount: 0,
  audioCount: 0
})

const fetchStats = async () => {
  try {
    const response = await fetch('/api/stats', {
      headers: {
        Authorization: `Bearer ${userStore.token}`
      }
    })
    const data = await response.json()
    stats.value = data
  } catch (error) {
    console.error('获取统计数据失败:', error)
  }
}

onMounted(() => {
  fetchStats()
})
</script>

<style scoped>
.dashboard {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-content {
  text-align: center;
  padding: 20px 0;
}

.card-content h2 {
  margin: 0;
  font-size: 24px;
  color: #303133;
}
</style> 